package cnhy.salary.domain;

import cn.hutool.core.util.NumberUtil;
import cnhy.salary.domain.proxy.DailyWageProxy;
import com.easy.query.core.proxy.ProxyEntityAvailable;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

import ling.common.DataUtil;
import lombok.Data;
import com.easy.query.core.annotation.*;
import ling.common.domain.entity.*;
import lombok.var;

/**
 * 日工资;
 * @author : He-LiangLiang@Outlook.com
 * @date : 2025-5-26
 */
@ApiModel(value = "日工资",description = "")
@EntityProxy
@Table("pay_daily_wage")
@Data
public class DailyWage extends CU2Entity.LongId implements Serializable,Cloneable, ProxyEntityAvailable<DailyWage , DailyWageProxy> {

    /** 计算工资：绩效+加班+餐补+奖惩；休假绩效为0
     *
     */
   public void wageSetBy() {

       var typeWage = DataUtil.nullDefault(getFixedWage(), 0d);
       if (postType == 0)
           typeWage = DataUtil.nullDefault(getPieceworkWage(), 0d);
       else if (postType == 2)
           typeWage = DataUtil.nullDefault(getRatioWage(), 0d);
       if (Objects.equals(workingStatus, "1"))
           typeWage = 0d;
       setWage(typeWage
               + DataUtil.nullDefault(getOvertimePay(), 0d)
               + DataUtil.nullDefault(getMeal(), 0d)
               + DataUtil.nullDefault(getPerformance(), 0d)
               + DataUtil.nullDefault(getWorkingAge(), 0d)
               + DataUtil.nullDefault(getPostAllowance(), 0d));
   }

    /** 设置休假状态，如果设为1休假，则将相关工资项设为0，
     *  未使用，看需求
     * @param ws
     */
   public void workingStatusSet(String ws) {
       setWorkingStatus(ws);
       if (!Objects.equals(getWorkingStatus(), "1"))
           return;
       setOutputNum(0d);
       setFixedWage(0d);
       setPieceworkNum(0d);
       setPerformance(0d);
       setScoreAdd(0d);
       setWorkingAge(0d);
       setPostAllowance(0d);
   }

    /** 基数获取
     *
     * @param rank
     * @param mcfg
     */
    public void ratioBaseSet(int rank,MonthlyCfg mcfg) {
        if (mcfg == null) {
            setRatioBase(0d);
            return;
        }
        switch (rank) {
            case 0:
                setRatioBase(mcfg.getLv1());
                break;
            case 1:
                setRatioBase(mcfg.getLv2());
                break;
            case 2:
                setRatioBase(mcfg.getLv3());
                break;
            default:
                setRatioBase(mcfg.getLv1());
        }
    }

   public void typeWageSet() {
       var dailyWage = this;
       dailyWage.setPieceworkWage(DataUtil.nullDefault(dailyWage.getPieceworkNum(), 0d) * DataUtil.nullDefault(dailyWage.getPieceworkPost(), 0d));
       // 系数*产出/10000=分值,分值*基数=工资
       dailyWage.setScore(DataUtil.nullDefault(dailyWage.getRatio(), 0d) * DataUtil.nullDefault(dailyWage.getOutputNum(), 0d) / 10000);
       dailyWage.setScore(NumberUtil.round(dailyWage.getScore(), 1).doubleValue());
       var totalScore = DataUtil.nullDefault(dailyWage.getScore(), 0d) + DataUtil.nullDefault(dailyWage.getScoreAdd(), 0d);
       //totalScore= NumberUtil.round(totalScore,2).doubleValue();
       dailyWage.setRatioWage(totalScore * DataUtil.nullDefault(dailyWage.getRatioBase(), 0d));
       dailyWage.setRatioWage(NumberUtil.round(dailyWage.getRatioWage(), 2).doubleValue());
   }

    /** 使用指定基数计算工资，用于日工资，实际与预估对比
     *
     * @param base
     * @return
     */
    public Double calcRatioWageByBase(Double base) {
        if (postType != 2)
            return getWage();
        if(base==null||getScore()==null)
            return null;

        var newRatioWage= getScore()*base;

      return newRatioWage
                + DataUtil.nullDefault(getOvertimePay(), 0d)
                + DataUtil.nullDefault(getMeal(), 0d)
                + DataUtil.nullDefault(getPerformance(), 0d);
    }

    
    String remark;
    /**  */
    /*
    @Column(primaryKey = true)
    @ApiModelProperty(value = "",notes = "")
    private Long id ;
    */
    
    /** 时间 */
    @Excel(name = "日期",dateFormat ="yyyy-MM-dd")
    @ApiModelProperty(value = "时间",notes = "")
    @EasyWhereCondition(type = EasyWhereCondition.Condition.GREATER_THAN_EQUAL)
    private Date time ;

    @ApiModelProperty(value = "时间2-搜索使用",notes = "")
    @EasyWhereCondition(type = EasyWhereCondition.Condition.LESS_THAN_EQUAL,propName = "time")
    @ColumnIgnore
    private Date time2 ;
   
    /**  */
    @ApiModelProperty(value = "",notes = "")
    @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
    private Long userId ;
     
   
    /** 员工姓名 */
    @Excel(name = "员工名称")
    @ApiModelProperty(value = "员工姓名",notes = "")
    @EasyWhereCondition
    private String userName ;
     
   
    /** 产线名称 */
    @Excel(name = "产线名称")
    @ApiModelProperty(value = "产线名称",notes = "")
    @EasyWhereCondition
    private String lineName ;
     
   
    /** 岗位-班组名称 */

    @ApiModelProperty(value = "岗位-班组名称",notes = "")
    private String lv2Name ;
     
   
    /** 岗位-班组id */
    @ApiModelProperty(value = "岗位-班组id",notes = "")
    @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
    private Long lv2Id ;
     
   
    /** 岗位名称 */
    @Excel(name = "岗位名称")
    @ApiModelProperty(value = "岗位名称",notes = "")
    private String postName ;
     
   
    /** 岗位id */
    @ApiModelProperty(value = "岗位id",notes = "")
    private Long postId ;

    @Excel(name = "系数")
     @ApiModelProperty(value = "系数",notes = "")
     private Double ratio ;
    /** 系数工资 */
    @Excel(name = "系数工资")
    @ApiModelProperty(value = "系数工资",notes = "")
    private Double ratioWage ;

     /** 预估基数 */
     @ApiModelProperty(value = "预估基数",notes = "")
     private Double ratioBase ;

    @ApiModelProperty(value = "实际基数",notes = "")
    private Double ratioBaseFinal ;
    /** 产出 */
    @Excel(name = "产出")
    @ApiModelProperty(value = "产出",notes = "")
    private Double outputNum ;
     

    /** 得分 */
    @ApiModelProperty(value = "得分",notes = "")
    private Double score ;
     
   
    /** 固定日薪 */
    @Excel(name = "固定薪资")
    @ApiModelProperty(value = "固定薪资",notes = "")
    private Double fixedWage ;
     
   
    /** 计件工资 */
    @Excel(name = "计件工资")
    @ApiModelProperty(value = "计件工资",notes = "")
    private Double pieceworkWage ;

     /** 岗位设置的月固定日薪 */
     @ApiModelProperty(value = "岗位设置的月固定日薪",notes = "")
     private Double fixedPost ;


     /** 岗位设置的计件单价 */
     @ApiModelProperty(value = "岗位设置的计件单价",notes = "")
     private Double pieceworkPost ;

     @ApiModelProperty(value = "岗位类型:0计件、1固定、2系数",notes = "")
     @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
     Integer postType;

     @ApiModelProperty(value = "级别：0普通，1班长，2主任",notes = "")
     @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
     Integer postRank;

    @ApiModelProperty(value = "postRank查询使用",notes = "")
    @EasyWhereCondition(type = EasyWhereCondition.Condition.IN,propName = "postRank")
    @ColumnIgnore
    Integer[] postRank2;
    /** 加班费，小时加班费*时长 */
    @Excel(name = "加班费")
    @ApiModelProperty(value = "加班费，小时加班费*时长",notes = "")
    private Double overtimePay ;


     /** 计件数 */
     @ApiModelProperty(value = "计件数",notes = "")
     private Double pieceworkNum ;


     /** 加班时长 */
     @ApiModelProperty(value = "加班时长",notes = "")
     private Double overtimeNum ;



     /** 0草稿，1已确认 */
     @ApiModelProperty(value = "0草稿，1已确认",notes = "")
     private String status ;

 /** 0正常，1休假，2全天请假 */
 @ApiModelProperty(value = "0正常，1休假,2全天请假",notes = "")
 @Excel(name = "上班状态",readConverterExp = "0=正常,1=休假,2=全天请假")
@EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
 private String workingStatus ;


 /** 0主岗，1临时岗副岗 */
 @ApiModelProperty(value = "0主岗，1临时岗副岗",notes = "")
 private String postStatus ;
     /** 日工龄工资 */
     @ApiModelProperty(value = "日工龄工资",notes = "")
     @Excel(name = "日工龄工资")
     private Double workingAge ;

    /** 日岗位津贴 */
    @ApiModelProperty(value = "日岗位津贴",notes = "")
    @Excel(name = "日岗位津贴")
    private Double postAllowance ;


    /** 考核分数 */
    @Excel(name = "考核分数")
    @ApiModelProperty(value = "考核分数",notes = "额外的附加分")
    private Double scoreAdd ;

    /** 其他补贴：工伤补贴 */
    @ApiModelProperty(value = "工伤补贴",notes = "")
    @Excel(name = "工伤补贴")
      Double otherWage;

    /** 餐补 */
    @Excel(name = "餐补")
    @ApiModelProperty(value = "餐补",notes = "")
    private Double meal ;
     
   
    /** 奖罚 */
    @Excel(name = "奖惩")
    @ApiModelProperty(value = "奖罚",notes = "")
    private Double performance ;

     /**  */

     @ApiModelProperty(value = "",notes = "")
     @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
     private Long deptId ;


     /** 部门名称 */
     @Excel(name = "部门名称")
     @ApiModelProperty(value = "部门名称",notes = "")
     private String deptName ;

    /** 日工资 */
    @ApiModelProperty(value = "日工资",notes = "")
    @Excel(name = "日应发工资")
    private Double wage ;


    /** 排序 */
    @ApiModelProperty(value = "排序",notes = "")
    private Integer orderNum;
}